// copyright 1993 Michael B. Johnson; some portions copyright 1994, MIT
// see COPYRIGHT for reuse legalities
//

#import "RIBPolygon.h"


@implementation RIBPolygon

+ initialize { return [RIBPolygon setVersion:1], self; }

- (BOOL)hasBoundingBox { return YES; }

- init
{
  [super init];

  nVertices = 0;

  return self;
}

- setNVertices:(RtInt)newNVertices 
     n:(int)newN tokens:(RtToken *)newTokens parms:(RtPointer *)newParms archiveVector:(char **)newArchiveVector
     printfTypeVector:(int *)newPrintfTypeVector printfNVector:(int *)newPrintfNVector
{  
   nVertices = newNVertices;
   howManyPoints = nVertices;
   [self setN:newN tokens:newTokens parms:newParms archiveVector:newArchiveVector printfTypeVector:newPrintfTypeVector printfNVector:newPrintfNVector];

   dirtyBoundingBox = TRUE;
   return self;
}

- setNVertices:(RtInt)newNVertices { nVertices = newNVertices; dirtyBoundingBox = TRUE; return self; }

- (RtInt)nVertices { return nVertices; }
- (int)n { return n; }
- (RtToken *)tokens { return tokens; }
- (RtPointer *)parms { return parms; }


- (BOOL)theSameAs:otherRIBCommand
{
  if (nVertices != [otherRIBCommand nVertices])
  {  return NO;
  }

  return [super theSameAs:otherRIBCommand];
}


- renderSelf:(WW3DCamera *)camera startingAt:(RtFloat)shutterOpenTime endingAt:(RtFloat)shutterCloseTime
{
  RiPolygonV(nVertices, n, tokens, parms);
  return self;
}


- (BOOL)isMotionBlurrable { return YES; }

- writeEve:(NXStream *)stream atTabLevel:(int)tab
{
   int  i;


   for (i = 0; i < tab; i++)
   {  NXPrintf(stream, "\t");
   }
   NXPrintf(stream, "Polygon ");
   [super writeParameterList:stream];
   return self;
}

#define typeVector "i"
#define typeValues &nVertices

- read:(NXTypedStream*)stream 
{
    int version;


    [super read:stream];

    version = NXTypedStreamClassVersion(stream,"RIBPolygon");
    if (version == 0) NXReadTypes(stream,"i",&version), version=1;
    if (version == 1)
    {  NXReadTypes(stream,typeVector,typeValues);
    } 
    else 
    {
    }
    return self;
}

- write:(NXTypedStream*)stream 
{
    [super write:stream];

    NXWriteTypes(stream,typeVector, typeValues);

    return self;
}


@end
